<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<title>竞技之星</title>
<link href="${path }/resource/css/scale-css.css" type="text/css" rel="stylesheet" />
<!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<script type="text/javascript" src="${path }/resource/js/scale.js"></script>
</head>

<body class="body-bg">
<div class="div-container">
<div class="title-bg">
			<div class="div-title">竞技之星</div><br>
			<div class="sub-title" style="margin-top: -290px;margin-left: 260px;">跑得快</div>
		</div>
		<div class="div-bg div-line-bg5"></div>
		
		<div class="div-content" style="margin-top: -1px;">跑得快帐号 : <span id="pdkId">${gameUser.userid }</span><br></div>
		<div class="div-content" style="margin-top: -1px;">跑得快余额 : <span id="pdkBalance ">${gameUser.diamondnum }</span> 钻石<br></div>
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		
		<div class="div-content" style="margin-top: -1px;">选择要绑定的俱乐部 :</div>
		<div class="div-content1" style="margin-top: -30px;">
		<select class="select-bg" id="dictId" name="dictId" onchange="choiceTip()">
				<!-- <option value="">--请选择--</option> -->
				<c:if test="${list ne null }">
					<c:forEach items="${list }" var="dict">
						<option value="${dict.id }">${dict.content}</option>
					</c:forEach>
				</c:if>
		</select>
		</div>
		
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		<div class="div-content" style="margin-top: -1px;">请输入该俱乐部注册手机号 :</div>
		<div class="div-content1" style="margin-top: -30px;">
			<input class="input-text2" type="text" id="tel" 
			<c:if test="${!empty bindTel}">value="${bindTel}" readonly="readonly"</c:if>
			/>
			<span class="div-btn" onclick="checkTel()" id="checkTel" >验证</span>
		</div>
		
		<div class="div-bg div-line-bg2" style="margin-top: -1px;"></div>
		<div class="div-content" style="margin-top: -1px;">请输入手机验证码 :</div>
		<div class="div-content1" style="margin-top: -30px;">
			<input class="input-text2" type="text" id="telCode" name="telCode"/>
		</div>
		
		<div class="div-bg div-line-bg120">
			<span class="div-btn div-font-size"  id="login" >登录</span>
			<span class="div-btn div-font-size" onclick="closeWindow()">关闭</span>
		</div>
	</div>
</body>
<script type="text/javascript">
var InterValObj; //timer变量，控制时间  
var count = 60; //间隔函数，1秒执行  
var curCount;//当前剩余秒数  
var code = ""; //验证码  
var pdkId = $("#pdkId").text();

	function closeWindow(){
		if(window.confirm("您确定要退出吗？")){
			 window.location.href="about:blank";
			 window.close();
	}
	}
	function login(){
		var dictId = $("#dictId").val();
		var tel = $("#tel").val().trim();
		var telCode = $("#telCode").val().trim();
		if(dictId==""){
			alert("转账俱乐部不能空！");
		}else if(telCode==""){
			alert("验证码不能为空！");
		}else if(pdkId==""||pdkId==null){
			alert("当前页面已过期，请关闭后重新访问！");
		}else{
			$("#login").attr("onclick","");
			$.ajax({
			    type: "post",
			    url: "${path}/transfer/checkTelCode",     
			    data: {"telCode":telCode},    
			    success: function(data) {
			    	if(data.code=='ok'){
			    		location.href="${path}/transfer/toTransferApply";
			    	}else{
			    		$("#login").attr("onclick","login()");
			    		alert(data.msg);
			    	}
			    },
			    error: function(data) {
			    	$("#login").attr("onclick","login()");
			    	alert("网络繁忙，请稍候再试！");
			    }
			    });
		}
	}
	
	//短信验证
	function checkTel(){
		var dictId = $("#dictId").val();
		var tel = $("#tel").val().trim();
		if(!tel.match(/^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/)){
			alert("手机号码格式不正确！");
		}else if(tel==""||tel==null){
			alert("手机号码不能为空！");
		}else if(dictId==""){
			alert("请选择转账俱乐部！");
		}
		else{
			$("#checkTel").text("正在发送…"); 
	        $("#checkTel").attr("onclick","");
			curCount = count;
			$.ajax({
			    type: "post",
			    url: "${path}/transfer/checkTel",     
			    data: {"dictId":dictId,
			    		"tel":tel},    
			    success: function(data) {
			    	if(data.code=='ok'){
			    		$("#login").attr("onclick","login()");
			    		InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
			    	}else{
			    		$("#checkTel").text("验证");
			    		$("#checkTel").attr("onclick","checkTel()");
			    		alert(data.msg);
			    	}
			    },
			    error: function(data) {
			    	$("#checkTel").text("验证"); 
			    	$("#checkTel").attr("onclick","");
			    	alert("网络繁忙，请稍候再试！");
			    }
			    });
		}
	}
	
	function SetRemainTime() {  
	    if (curCount == 0) {                  
	        window.clearInterval(InterValObj);//停止计时器  
	        $("#checkTel").attr("onclick","checkTel()");//启用按钮  
	        $("#checkTel").text("重新验证");  
	    }  
	    else {  
	        curCount--;  
	        $("#checkTel").text(curCount + "s");  
	    }  
	}
	
	function choiceTip(){
		alert("俱乐部一旦绑定将不能解绑或更换，请谨慎选择！");
	}
</script>
</html>